﻿//-----------------------------------------------------------------------
// <copyright file="ProblemImplementation.cs" company="Numbrella foundation">
// Copyright (c) Numbrella foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Numbrella.Interaction
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;    
    using System.Runtime.Serialization;

    /// <summary>
    /// Contains some necessary information about problem implementation.
    /// </summary>
    [DataContract]
    public class ProblemImplementation
    {
        #region Fields

        /// <summary>
        /// Contains raw bytecode of assembly that contains implementation of the problem.
        /// </summary>
        [DataMember]
        private byte[] rawAssembly;

        #endregion

        #region Initialization

        /// <summary>
        /// Initializes a new instance of the <see cref="ProblemImplementation"/> class.
        /// </summary>
        /// <param name="serializerKnownTypeNames">Assembly qualified names of additional types for WCF serializer.</param>
        /// <param name="rawAssembly">Bytecode of the assembly that contains problem implementation.</param>
        public ProblemImplementation(IEnumerable<string> serializerKnownTypeNames, byte[] rawAssembly)
        {
            if (serializerKnownTypeNames == null)
                throw new ArgumentNullException("serializerKnownTypeNames");
            if (rawAssembly == null)
                throw new ArgumentNullException("rawAssembly");

            this.rawAssembly = (byte[])rawAssembly.Clone();
            this.SerializerKnownTypeNames = new List<string>(serializerKnownTypeNames).AsReadOnly();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets additional types for WCF serializer.
        /// </summary>
        [DataMember]
        public ReadOnlyCollection<string> SerializerKnownTypeNames { get; private set; }

        #endregion

        #region Methods

        /// <summary>
        /// Gets raw bytecode of assembly that contains implementation of the problem.
        /// </summary>
        /// <returns>Raw bytecode of assembly that contains implementation of the problem.</returns>
        public byte[] GetRawAssembly()
        {
            return (byte[])this.rawAssembly.Clone();
        }

        #endregion
    }
}
